/*
 * @Description: 
 * @Author: charles
 * @Date: 2021-12-16 09:39:13
<<<<<<< HEAD
 * @LastEditors: 宋佳馨 song2005315@qq.com
 * @LastEditTime: 2025-09-26 16:24:27
=======
 * @LastEditors: 刘佳欢 2173558681@qq.com
 * @LastEditTime: 2025-09-26 22:00:19
>>>>>>> 1576b6416372d97f4d59de56fc7f862b4da9250b
 */
import Vue from 'vue'
import Router from 'vue-router'
import OrderList from '@/pages/am/order/List.vue'
import Details from '@/pages/am/order/Details.vue' // 已引入，无需重复引入

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes：无需权限即可访问的基础路由
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '监测大屏', icon: '地理位置' }
    }]
  },

  // 1. 工单列表路由（原有）
  {
    path: '/am/order/List',
    component: Layout,
    redirect: '/am/order/List', // 修正 redirect：默认指向自身，而非 dashboard
    children: [{
      path: '', // 子路由路径为空，匹配父路由完整路径
      name: 'OrderList',
      component: OrderList,
      meta: { title: '工单列表', icon: 'el-icon-s-order' }
    }]
  },

  // 2. 新增：Details 详情页路由（与工单列表同级）
  {
    path: '/am/order/Details', // 路径与 Details.vue 实际位置对应，保持层级一致
    component: Layout,
    hidden: true, // 详情页不在侧边栏显示（仅通过列表页跳转访问）
    children: [{
      path: '', // 子路由路径为空，匹配父路由完整路径
      name: 'OrderDetails', // 路由名称唯一，与列表页区分
      component: ()=>import('@/pages/am/order/Details.vue'),
      meta: { title: '工单详情', activeMenu: '/am/order/List' } // activeMenu：跳转后侧边栏仍高亮“工单列表”
    }]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由
}

export default router